﻿// 功能：
// 描述：
// 作者：温伟鹏
// 日期：2010/5/17 21:16:01

using System;
using System.Collections.Generic;
using System.Text;
using MeizuSDK.Presentation;

namespace Demo
{
    class PopupProgressWindow : DemoWindowBase
    {
        private PopupProgress progress;
        private ProgressBar progressBar;
        private System.Windows.Forms.Timer timer;

        public PopupProgressWindow()
        {
            timer = new System.Windows.Forms.Timer();
            timer.Interval = 100;
            timer.Tick += new EventHandler(timer_Tick);

            progress = new PopupProgress();
            progress.TitleText = "剩余时间10秒";
            progress.NoteText = "进度条对话框";

            progressBar = new ProgressBar();
            progressBar.Location = new System.Drawing.Point(10, 10);
            progressBar.Size = new System.Drawing.Size(300, 10);

            toolbar.SetTextButton(ToolBarButtonIndex.MiddleTextButton, true, true, "Open PopupProgress");
            toolbar.SetTextButton(ToolBarButtonIndex.RightTextButton, true, true, "进度条");

            Controls.Add(progressBar);
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if (progress.Value == 100)
            {
                progress.Value = 0;
            }
            else
            {
                progress.Value++;
            }

            if (progressBar.Value == 100)
            {
                progressBar.Value = 0;
            }
            else
            {
                progressBar.Value++;
            }

            progress.TitleText = string.Format("剩余时间{0}秒", (float)((progress.Maximum - progress.Value)) / (float)(10));
        }

        protected override void toolbar_ButtonClick(object sender, MeizuSDK.Presentation.ToolBar.ButtonEventArgs e)
        {
            base.toolbar_ButtonClick(sender, e);

            if (e.Index == ToolBarButtonIndex.MiddleTextButton)
            {
                progress.TitleText = "剩余时间10秒";
                progress.Value = 0;
                progress.Show(HWnd,true,true,true);
                timer.Enabled = true;
            }
            else if(e.Index == ToolBarButtonIndex.RightTextButton)
            {
                timer.Enabled = true;
            }
        }

        protected override void OnMzCommand(uint wParam, uint lParam)
        {
            base.OnMzCommand(wParam, lParam);

            uint id = NativeMethods.LOWORD(wParam);

            // 点击了 取消按钮
            if(id == 1)
            {
                timer.Enabled = false;

                progress.Hide();
            }
        }
    }
}
